package servlet;

import hbase.HbaseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author:gaomj
 * @Date:Created in 2022/3/13 9:40
 */

@WebServlet(name = "ServletDeleteRow",urlPatterns = "/HbaseServletDeleteRow")
public class ServletDeleteRow extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String tname = "studenttable";
        String id = request.getParameter("id");
        int msg = 0;
        if(HbaseUtil.deleteRow(tname, id)){
            msg = 1;
        }else{
            msg = -1;
        }
        if(msg==1){
            response.setCharacterEncoding("utf-8");
            response.setContentType("text/html;charset=utf-8");
            PrintWriter out = response.getWriter();
            out.println("删除成功");
            out.flush();
            out.close();
            response.setCharacterEncoding("utf-8");
            request.getRequestDispatcher("/supermarket.jsp").forward(request,response);
        }else{
            response.setCharacterEncoding("utf-8");
            response.setContentType("text/html;charset=utf-8");
            PrintWriter out = response.getWriter();
            out.println("删除信息失败，请重新输入");
            out.flush();
            out.close();
            response.setCharacterEncoding("utf-8");
            request.getRequestDispatcher("/supermarket.jsp").forward(request,response);
        }
    }
}
